package com.tiancheng.onecode.controller.api.merchant;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dtflys.forest.annotation.Get;
import com.tiancheng.onecode.entity.MerchantVoiceDevice;
import com.tiancheng.onecode.entity.PlatformMerchantRegInvite;
import com.tiancheng.onecode.model.request.admin.AddMerchantVoiceDeviceReq;
import com.tiancheng.onecode.model.request.admin.PlatformMerchantRegInviteAddReq;
import com.tiancheng.onecode.model.request.admin.PlatformMerchantRegInviteUpdateReq;
import com.tiancheng.onecode.model.response.Result;
import com.tiancheng.onecode.model.response.api.QueryDeviceTypeRes;
import com.tiancheng.onecode.service.IMerchantVoiceDeviceService;
import com.tiancheng.onecode.service.IPlatformMerchantRegInviteService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: kellen
 * @Description: 子商户语音音响管理
 * @Date: create in 2025/02/27 16:36
 */
@Controller
@RequestMapping("/api/b/merchantDevice")
public class MerchantDeviceApiMerchantController {

    @Resource
    private IMerchantVoiceDeviceService merchantVoiceDeviceService;

    /**
     * 添加语音设备
     * @param platformMerchantId 平台商户id
     * @return
     */
    @GetMapping(value = "/queryDeviceType")
    @ResponseBody
    public Result<List<QueryDeviceTypeRes>> queryDeviceType(@RequestParam(name = "platformMerchantId") Long platformMerchantId) {
        List<QueryDeviceTypeRes> deviceTypeRes = merchantVoiceDeviceService.queryDeviceType(platformMerchantId);
        return Result.success(deviceTypeRes);
    }

    /**
     * 添加语音设备
     *
     * @param addMerchantVoiceDeviceReq 平台编码
     * @return
     */
    @PostMapping(value = "/addDevice")
    @ResponseBody
    public Result<MerchantVoiceDevice> addDevice(@RequestBody @Valid AddMerchantVoiceDeviceReq addMerchantVoiceDeviceReq) {
        MerchantVoiceDevice merchantVoiceDevice = merchantVoiceDeviceService.addDevice(addMerchantVoiceDeviceReq);
        return Result.success(merchantVoiceDevice);
    }

    /**
     * 查询设备列表
     *
     * @param platformMerchantId 平台商户id
     * @return
     */
    @GetMapping(value = "/queryDevices")
    @ResponseBody
    public Result<List<MerchantVoiceDevice>> queryDevices(@RequestParam(name = "platformMerchantId") Long platformMerchantId) {
        List<MerchantVoiceDevice> devices = merchantVoiceDeviceService.queryByPlatformMerchantId(platformMerchantId,true);
        return Result.success(devices);
    }

    /**
     * 移除设备
     *
     * @param id 设备绑定id
     * @return
     */
    @DeleteMapping(value = "/remove")
    @ResponseBody
    public Result remove(@RequestParam(name = "id") Long id) {
        merchantVoiceDeviceService.remove(id);
        return Result.success();
    }


}
